{extend name="base/base" /}
{block name="style"}
<style type="text/css">
.layui-table-cell{
     height: auto!important;
     white-space: normal;
}
</style>
{/block}
{block name="content"}
  <table id="table" lay-filter="table"></table> 

{/block}
{block name="script"}
<script>
layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    ,height: 'full-150'
    ,url: '/admin/coin/walletList/' //数据接口
    ,limit:20
    ,page: true //开启分页
    ,id:'reload'
    ,cols: [[ //表头
      {field:'id', title: 'ID', width: 100}
      ,{field:'icon', title: '图标', width: 80,templet: function(d){
        return '<img src="'+d.icon+'" style="width:50px;height:50px">'
      }}
      ,{field:'wallet', title: '钱包名称', width: 200}
      ,{field:'name', title: '钱包名称', width: 200}
      ,{field:'price', title: '价值（枚/美金）', width: 200,edit: 'text'}
    ]]
  }); 
  ///监听单元格编辑
  table.on('edit(table)', function(obj){
    var value = obj.value //得到修改后的值
    ,data = obj.data //得到所在行所有键值
    ,field = obj.field; //得到字段
    var post_data = {
      id:data.id,
      field:field,
      value:value
    };
    $.ajax({
            url:"{:url('admin/coin/editWallet')}",
            type:"POST",
            data:post_data,
            success:function(ret){
                if (ret.code == 0) {
                  layer.msg('操作成功');
                  $(".layui-laypage-btn")[0].click();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        });
  });
});

</script>
{/block}
